using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/****************************************************
// 功能：血条显示Item
// | Talk To [ 聊来改善地区金融服务环境，助力企业发展 ]
// | Copyright (c) 2021-2025 聊来 All rights reserved.
// | Licensed ( <a href="http://www.apache.org/licenses/LICENSE-2.0">聊来</a> )
// | @Author: 贯彻己道的云 <18970881148@qq.com>
// | DateTime: 2025/3/27 14:59:20
*****************************************************/

public abstract class ItemHp: BaseWindow
{
    public RectTransform rect;
    public Image imageProgress;
    private Transform rootTrans;
    private int hpVal;

    protected bool isFriend;

    public virtual void InitItem(MainLogicUnit unit, Transform root, int hp)
    {
        var selfTeam = TeamEnum.None;
        selfTeam = BattleController.Instance.GetCurrentUserTeam() == TeamEnum.Blue ? TeamEnum.Blue : TeamEnum.Red;
        isFriend = unit.IsTeam(selfTeam);

        imageProgress.fillAmount = 1;
        rootTrans = root;
        hpVal = hp;
    }

    public void UpdateHpProgress(int newVal)
    {
        SetActive(gameObject, newVal != 0);
        imageProgress.fillAmount = newVal * 1.0f / hpVal;
    }

    public virtual void SetStateInfo(StateEnum state, bool show) { }

    private void Update()
    {
        if (!rootTrans) return;
        var scaleRate = 1.0f * Constants.SCREEN_STANDARD_HEIGHT / Screen.height;
        if (Camera.main == null) return;
        Vector3 screenPos = Camera.main.WorldToScreenPoint(rootTrans.position);
        rect.anchoredPosition = screenPos * scaleRate;
    }

    
}

public enum StateEnum
{
    None,
    Silenced,
    Knockup,
    Stunned,
    
    Invincible,
    Restricted
}
